/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : structs_internal
	/// </summary>
	public class CenterLoadPlayerPOD : IPOD 
    {
        public readonly static Func<CenterLoadPlayerPOD> FACTORY = () => new CenterLoadPlayerPOD();
		public static Func<CenterLoadPlayerPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public ChatRoomPOD chatRoom;
		/// <summary>
        /// 
        /// </summary>
        private List<FriendPOD> m_friends;
		/// <summary>
        /// 
        /// </summary>
		public string playerName;
		/// <summary>
        /// 
        /// </summary>
		public LoadOperationEventDataPOD loadOpEventDataPOD;
		
		
        public List<FriendPOD> friends
        {
            get
            {
                if(m_friends == null)
                {
                    m_friends = new();
                }
                return m_friends;
            }
            private set => m_friends = value;
        }
        public List<FriendPOD> unsafe_friends
        {
        	get => m_friends;
        	set => m_friends = value;
        }
		
		/*-- constructors --*/
		public CenterLoadPlayerPOD() {}
		public CenterLoadPlayerPOD(ChatRoomPOD chatRoom, List<FriendPOD> friends, string playerName, LoadOperationEventDataPOD loadOpEventDataPOD) {
			this.chatRoom = chatRoom;
			this.m_friends = friends;
			this.playerName = playerName;
			this.loadOpEventDataPOD = loadOpEventDataPOD;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_pod(chatRoom);
            _out.Write_list_pod(m_friends);
            _out.Write_string(playerName);
            _out.Write_pod(loadOpEventDataPOD);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            chatRoom = _in.Read_pod<ChatRoomPOD>(ChatRoomPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_friends = _in.Read_list_pod<FriendPOD>(FriendPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            playerName = _in.Read_string();
            if(!_in.HasRemaining()) return;
            loadOpEventDataPOD = _in.Read_pod<LoadOperationEventDataPOD>(LoadOperationEventDataPOD.DynamicFactory);
        }
		
		public CenterLoadPlayerPOD Clone() {
            CenterLoadPlayerPOD o = DynamicFactory();
            if (chatRoom != null) {
                o.chatRoom = chatRoom.Clone();
            }
            if (m_friends != null) {
                o.m_friends = m_friends.ConvertAll(o => o?.Clone());
            }
            o.playerName = playerName;
            if (loadOpEventDataPOD != null) {
                o.loadOpEventDataPOD = loadOpEventDataPOD.Clone();
            }
            return o;
        }
        
        public void Clear() {
            chatRoom = default;
            m_friends = default;
            playerName = default;
            loadOpEventDataPOD = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "CenterLoadPlayerPOD [";
			str += "chatRoom=";
			str += chatRoom;
			str += ", friends=";
			str += m_friends.ToString<FriendPOD>();
			str += ", playerName=";
			str += playerName;
			str += ", loadOpEventDataPOD=";
			str += loadOpEventDataPOD;
			str += "]";
			return str;
		}
		
	}
}